<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>地理编码</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=25f055ddfa07adbacb2dd614fcbd6780&plugin=AMap.Geocoder"></script>
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
</head>
<body>
    <div id="container"></div>
    <div id="tip">

        <span id="result"></span>
    </div>
    <script type="text/javascript">
        var datas = ["安阳市",'南京市','北京市','南宁市','西安市','拉萨市','广州市','西宁市','上海市'];

        var map = new AMap.Map("container", {
            resizeEnable: true,
            zoom:5,
            center: [108.824032,34.167488]
        });

        for (var i = 0; i < datas.length; i++) {
            geocoder(datas[i]
) 
        }



        function geocoder(data) {
            var geocoder = new AMap.Geocoder({
           // city: "010", //城市，默认：“全国”
            radius: 1000 //范围，默认：500
        });
        //地理编码,返回地理编码结果
        geocoder.getLocation(data, function(status, result) {
            console.log(result)
            if (status === 'complete' && result.info === 'OK') {
                geocoder_CallBack(result);
            }
        });
    }
    function addMarker(i, d) {
        var marker = new AMap.Marker({
            map: map,
            position: [ d.location.getLng(),  d.location.getLat()],
            content:'<span>yangyue</span>'
        });

        console.log(marker);


    }
    //地理编码返回结果展示
    function geocoder_CallBack(data) {
        // console.log(data)
        var resultStr = "";
        //地理编码结果数组
        var geocode = data.geocodes;
        for (var i = 0; i < geocode.length; i++) {
            //拼接输出html
            resultStr += "<span style=\"font-size: 12px;padding:0px 0 4px 2px; border-bottom:1px solid #C1FFC1;\">" + "<b>地址</b>：" + geocode[i].formattedAddress + "" + "&nbsp;&nbsp;<b>的地理编码结果是:</b><b>&nbsp;&nbsp;&nbsp;&nbsp;坐标</b>：" + geocode[i].location.getLng() + ", " + geocode[i].location.getLat() + "" + "<b>&nbsp;&nbsp;&nbsp;&nbsp;匹配级别</b>：" + geocode[i].level + "</span>";
            addMarker(i, geocode[i]);
        }
        map.setFitView();

        document.getElementById("result").innerHTML = resultStr;
    }
</script>
</body>
</html>                     

